<?php
/**
 * 注释不留名,代码随便用
 * Date: 2019/7/17
 * Time: 14:35
 */
namespace app\store\validate;
use app\common\library\Sms;
use think\Validate;

class SettlerValidate extends Validate
{
    protected $rule = [
        'mobile'    => 'require|isMobile',
        'name|姓名' => 'require|length:2,6',
        'gender|性别' => 'require|in:0,1,2,',
        'nation|民族' => 'require|length:1,10',
        'origin|籍贯' => 'require|length:2,10',
        'residence|现居地' => 'require|length:2,255',
//        'qualification' => 'require|length:2,10',
        'position' => 'length:2,10',
        'evaluate'    => 'max:255',
    ];
    protected $message = [
        'mobile.require'    => '手机号不能为空！',
        'mobile.isMobile'   => '手机号格式不正确',
        'mobile.unique'     => '手机号已存在！',
        'fullname.require'  => '姓名不能为空！',
        'fullname.length'   => '姓名格式不正确!',
        'idcard.require'    => '身份证号不能为空！',
        'idcard.isIdCard'   => '身份证号格式不正确！',
        'idcard.unique'     =>  '身份证号已存在！',
        'nation.require'    => '民族不能为空！',
        'nation.length'     => '民族格式不正确！',
        'origin.require'    => '籍贯不能为空！',
        'origin.length'     => '籍贯格式不正确！',
        'residence.require' => '现居地不能为空',
        'residence.length'  => '现居地格式不正确！',
        'qualification.require'     => '学历不能为空！',
        'qualification.length' => '学历格式不正确',
        'position'  => '职位填写有误！',
        'captcha.require'   => '验证码不能为空!',
        'captcha.checkCaptcha' => '验证码不正确！'
        ];

    public function isMobile($value, $rule){
        return isMobile($value);
    }

    public function isIdCard($value, $rule){
        return isIdCard($value);
    }

    public function checkCaptcha($value, $rule, $data) {
        return Sms::check($data['mobile'],$value, isset($data['event']) ? $data['event'] : '');
    }

}